package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.pojo.TbContentCategoryExample;
import com.dongdongshop.service.CategoryService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
@DubboService
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private TbContentCategoryMapper contentCategoryMapper;

    //查询全部分类信息
    @Override
    public List<TbContentCategory> getCategoryList(String name) {
        TbContentCategoryExample example = new TbContentCategoryExample();
        if (name != null && !"".equals(name)) {
            TbContentCategoryExample.Criteria criteria = example.createCriteria();
            criteria.andNameLike("%"+name+"%");
        }
        return contentCategoryMapper.selectByExample(example);
    }

    //增加内容分类
    @Override
    public void addCategory(TbContentCategory contentCategory) {
        contentCategoryMapper.insertSelective(contentCategory);
    }

    //回显内容分类信息
    @Override
    public TbContentCategory editCategory(Long id) {
        return contentCategoryMapper.selectByPrimaryKey(id);
    }

    //修改内容信息
    @Override
    public void updateCategory(TbContentCategory contentCategory) {
        contentCategoryMapper.updateByPrimaryKey(contentCategory);
    }

    //删除内容分类
    @Override
    public void deleteCategory(Long[] ids) {
        List<Long> list = Arrays.asList(ids);
        TbContentCategoryExample example = new TbContentCategoryExample();
        TbContentCategoryExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(list);
        contentCategoryMapper.deleteByExample(example);
    }
}
